//
//  DoubleBallPresentView.m
//  JINYUNCAI
//
//  Created by LiJonius on 16/3/1.
//  Copyright © 2016年 Jonius. All rights reserved.
//  当前其次 View

#import "BallLotteryFormView.h"

@interface BallLotteryFormView ()
/**
 *	@brief	//列数
 */
@property (nonatomic ,assign) NSInteger col;
/**
 *	@brief	//行数
 */
@property (nonatomic ,assign) NSInteger row;
/**
 *	@brief	//列高
 */
@property (nonatomic ,assign) NSInteger rowHeight;
/**
 *	@brief	 //行宽
 */
@property (nonatomic ,assign) NSInteger rowWidth;
/**
 *	@brief	//左边距
 */
@property (nonatomic ,assign) NSInteger left;
/**
 *	@brief	//右边距
 */
@property (nonatomic ,assign) NSInteger right;
/**
 *	@brief	//数组 《数组里面 按照列嵌套数组》
 */
@property (nonatomic ,strong) NSMutableArray* array;

/**
 *	@brief	//字体颜色数组 《1\数组里面 元素个数 和 array.count 要相同 2\数组中的color对象 不能用宏初始化》
 */
@property (nonatomic ,strong) NSArray* colorArray;

/**
 *	@brief	标题的字体颜色
 */
@property (nonatomic ,strong) UIColor* titleTextColor;
/**
 *	@brief	标题Label的 背景色
 */
@property (nonatomic ,strong) UIColor* titleBackGroundColor;
/**
 *	@brief	非标题Label的 背景色
 */
@property (nonatomic ,strong) UIColor* contentColor;

/**
 *	@brief	线的颜色
 */
@property (nonatomic ,strong) UIColor* lineColor;

/**
 *	@brief	是否画线
 */
@property (nonatomic) BOOL isLine;


@end

@implementation BallLotteryFormView

-(instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
    
        self.backgroundColor = [UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1.0];
        
        //[self initUI];
        
    }
    return self;
}

/**
 *	@brief	表格
 *
 *	@param 	frame 	frame
 *	@param 	mutableArray  存放数据的数组
 *	@param 	colorArray 	颜色数组 元素个数与mutableArray的个数要一致 ＝ 列数
 *	@param 	left 	左边距
 *	@param 	right 	右边距离
 *	@param 	RowHeight 	单元格高度
 *	@param 	rowWidth 	单元格宽度
 *  @param 	titleTextColor 	标题Label的 字体颜色
 *  @param 	titleBackGroundColor 	标题Label的 背景色
 *  @param 	contentColor 	非标题Label的 背景色
 *  @param 	lineColor 	线的颜色
 *  @param 	isLine      是否画线
 *
 *	@return	view
 */
-(instancetype)initWithFrame:(CGRect)frame andMutableArray:(NSMutableArray*)mutableArray andColorArray:(NSMutableArray*)colorArray andLeft:(NSInteger)left andRight:(NSInteger)right andRowHeight:(NSInteger)rowHeight andRowWidth:(NSInteger)rowWidth andTitleTextColor:(UIColor*)titleTextColor andTitleBackGroundColor:(UIColor*)titleBackGroundColor andContentColor:(UIColor*)contentColor andLineColor:(UIColor*)lineColor andIsLine:(BOOL)isLine
{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1.0];
        
        [self initUIWithMutableArray:mutableArray andColorArray:colorArray andLeft:left andRight:right andRowHeight:rowHeight andRowWidth:rowWidth andTitleTextColor:titleTextColor andTitleBackGroundColor:titleBackGroundColor andContentColor:contentColor andLineColor:lineColor andIsLine:isLine];
    }
    return self;
}

-(void)initUIWithMutableArray:(NSMutableArray*)mutableArray
                        andColorArray:(NSMutableArray*)colorArray
                        andLeft:(NSInteger)left
                        andRight:(NSInteger)right
                        andRowHeight:(NSInteger)rowHeight
                        andRowWidth:(NSInteger)rowWidth
                        andTitleTextColor:(UIColor*)titleTextColor
                        andTitleBackGroundColor:(UIColor*)titleBackGroundColor
                        andContentColor:(UIColor*)contentColor andLineColor:(UIColor*)lineColor
                        andIsLine:(BOOL)isLine
{

    ///用来计算有多少行
    NSArray* tempArray = mutableArray[0];
    
    
    self.colorArray = colorArray;
    self.left = left;
    self.right = right;
    self.rowWidth = rowWidth;
    self.rowHeight = rowHeight;
    self.col = mutableArray.count;
    self.row = tempArray.count;
    self.titleTextColor = titleTextColor;
    self.lineColor = lineColor;
    self.contentColor = contentColor;
    self.isLine = isLine;
    self.titleBackGroundColor = titleBackGroundColor;
    
    
    for (int i = 0; i < mutableArray.count; i++) {
        
        NSArray* array = mutableArray[i];
        
        for (int j = 0; j<array.count; j++) {
            
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(self.left + self.rowWidth * i, j * self.rowHeight, self.rowWidth, self.rowHeight)];
            label.textAlignment = NSTextAlignmentCenter;
            label.text = array[j];
            label.font = [UIFont systemFontOfSize:12];
            
            //
            if (j == 0) {
                
                label.backgroundColor = self.titleBackGroundColor;
                
                label.textColor = self.titleTextColor;
                
            }else{
                
                label.backgroundColor = self.contentColor;
                
                UIColor* color = self.colorArray[i];
                
                label.textColor = color;
                
                
                
            }
            [self addSubview:label];
            
        }
        
        
        
    }
    
    
    


    //RGBA(220, 220, 220, 1)
    
    if (self.isLine) {
        
        for (int i = 0 ; i < self.col + 1; i++) {
            
            UIView* line = [[UIView alloc]initWithFrame:CGRectMake(self.left + i * self.rowWidth, 0, 1, self.rowHeight * self.row)];
            line.backgroundColor = self.lineColor;
            [self addSubview:line];
        }
        
        for (int i = 0 ; i < self.row + 1; i++) {
            
            UIView* line = [[UIView alloc]initWithFrame:CGRectMake(self.left, i * self.rowHeight, Screen_width - self.left - self.right , 1)];
            line.backgroundColor =self.lineColor;
            [self addSubview:line];
        }
    }
    
    
}

///
-(instancetype)initWithLotteryFrame:(CGRect)frame andMutableArray:(NSMutableArray*)mutableArray{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1.0];
        
        [self initUIWithMutableArray:mutableArray];
    }
    return self;
}

-(void)initUIWithMutableArray:(NSMutableArray*)mutableArray

{
    UIColor* titleTextColor = RGBA(80, 80, 80, 1);
    
    UIColor* titleBackgroundColor = RGBA(252, 253, 247, 1);
    
    UIColor* color1 = [UIColor lightGrayColor];
    UIColor* color2 = [UIColor blackColor];
    UIColor* color3 = [UIColor redColor];
    NSArray* colorArray = @[color1,color2,color3];
    
    UIColor* contentColor= [UIColor whiteColor];
    UIColor* lineColor = RGBA(220, 220, 220, 1);
    
   
    
    ///用来计算有多少行
    NSArray* tempArray = mutableArray[0];
    
    
    self.colorArray = colorArray;
    self.left = 10;
    self.right = 10;
    self.rowWidth = (Screen_width -20)/3;
    self.rowHeight = 20;
    self.col = mutableArray.count;
    self.row = tempArray.count;
    self.titleTextColor = titleTextColor;
    self.lineColor = lineColor;
    self.contentColor = contentColor;
    self.isLine = YES;
    self.titleBackGroundColor = titleBackgroundColor;
    
    
    for (int i = 0; i < mutableArray.count; i++) {
        
        NSArray* array = mutableArray[i];
        
        for (int j = 0; j<array.count; j++) {
            
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(self.left + self.rowWidth * i, j * self.rowHeight, self.rowWidth, self.rowHeight)];
            label.textAlignment = NSTextAlignmentCenter;
            label.text = array[j];
            label.font = [UIFont systemFontOfSize:12];
            
            //
            if (j == 0) {
                
                label.backgroundColor = self.titleBackGroundColor;
                
                label.textColor = self.titleTextColor;
                
            }else{
                
                label.backgroundColor = self.contentColor;
                
                UIColor* color = self.colorArray[i];
                
                label.textColor = color;
                
                
                
            }
            [self addSubview:label];
            
        }
        
        
        
    }
    
    
    
    
    
    //RGBA(220, 220, 220, 1)
    
    if (self.isLine) {
        
        for (int i = 0 ; i < self.col + 1; i++) {
            
            UIView* line = [[UIView alloc]initWithFrame:CGRectMake(self.left + i * self.rowWidth, 0, 1, self.rowHeight * self.row)];
            line.backgroundColor = self.lineColor;
            [self addSubview:line];
        }
        
        for (int i = 0 ; i < self.row + 1; i++) {
            
            UIView* line = [[UIView alloc]initWithFrame:CGRectMake(self.left, i * self.rowHeight, Screen_width - self.left - self.right , 1)];
            line.backgroundColor =self.lineColor;
            [self addSubview:line];
        }
    }
    
    
    
}

@end
